import 'package:sainbainu/common/utils/util.dart';

class UserListResponse {
  List<UserItemResponse> rows;
  int total;

  UserListResponse({
    required this.rows,
    required this.total,
  });

  factory UserListResponse.fromJson(Map<String, dynamic> json) =>
      UserListResponse(
        total: json['total'] as int,
        rows: (json['rows'] as List)
            .map((e) => UserItemResponse.fromJson(e))
            .toList(),
      );
}

class UserItemResponse {
  int? customerId;
  String? customerName;
  String? avatar;
  String? intro;
  int followFlag; // 是否关注：0.否；1.是
  int officialFlag;
  String? officialName;
  String? uniqueTag;

  UserItemResponse({
    this.customerId,
    this.customerName,
    this.avatar,
    this.intro,
    this.followFlag = 0,
    this.officialFlag = 0,
    this.officialName,
    this.uniqueTag,
  });

  factory UserItemResponse.fromJson(Map<String, dynamic> json) =>
      UserItemResponse(
        customerId: json['customerId'] as int?,
        customerName: json['customerName'] as String?,
        avatar: json['avatar'] as String?,
        intro: json['intro'] as String?,
        followFlag: (json['followFlag'] as int?) ?? 0,
        officialFlag: (json['officialFlag'] as int?) ?? 0,
        officialName: json['officialName'] as String?,
        uniqueTag: Util.generateRandomString(),
      );

  Map<String, dynamic> toJson() => {
        'customerId': customerId,
        'customerName': customerName,
        'avatar': avatar,
        'intro': intro,
        'followFlag': followFlag,
        'officialFlag': officialFlag,
        'officialName': officialName,
      };
}
